package com.yang.aop;

import com.yang.imbatis.factory.YangFactoryBean;
import com.yang.imbatis.factory.YangInvocationHandler;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Proxy;

/**
 * @Description: 自定义后置处理器实现AOP功能
 * @author: Yang Qiang
 * @create: 2021-10-23 22:42
 */
@Component
public class YangProxyBeanFactoryProcessor implements BeanPostProcessor {
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
//		if (beanName.equals("n")){
//			Class<?>[] interfaces = bean.getClass().getInterfaces();
//			Object proxyInstance = Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, new YangInvocationHandler(bean));
//			return proxyInstance;
//		}

		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		return null;
	}
}
